.orig x3000

POWER
;========= Set up stack ===========
	ADD R6, R6, -4	;SP+4
	STR R7, R6, 2	; STORE RA
	STR R5, R6, 1	;STORE OLD FP
	ADD R5, R6, 0	;CREATE NEW FP
	STR R0, R5, 0	;STORE OLD R0
	STR R1, R5, -1	;STORE OLD R1
	STR R2, R5, -2	;STORE OLD R2
	ADD R6, R6, -2	;SP +2
	LDR R0, R5, 4	;LOAD A IN R0
	LDR R1, R5, 5	;LOAD B IN R1

	ADD R1 R1, -1	;SETTING UP CHECKS TO POWER & DECREMENT B
	BRZ DONE		;CHECKING FOR A^1
	BRN	ZEROPOWER	;CHECKING FOR A^0
	JSR POWER
	LDR R1, R6, 0	;LOAD RET VAL OF POWER
	;======== Multiply ======
	ADD R2, R0, 0	;MOVE A INTO R2
	NOTDONE
	ADD R2, R2, 0	;CHECK COUNTER
	BRZ DONE
	ADD R1, R1, R1;	R1+R1
	ADD R2, R2, -1	;DECREMENT COUNTER
	BRNZP NOT DONE
	BRNZP DONE
	ZEROPOWER
		AND R1, R1, 0
		ADD R1, R1, 1
	DONE
	STR R1, R5, 3	;STORE RET VAL
	
	LDR R0, R5, 0	;RESTORE OLD R0
	LDR R1, R5, -1	;RESTORE OLD R1
	LDR R1, R5, -2	;RESTORE OLD R2
	ADD R6, R5, 0	;MOVE SP TO CURRENT FP
	LDR R7, R5, #2	;RESTORE RET ADDR
	LDR R5, R5, #1	;RESTORE OLD FP
	ADD R6, R6, #3	;MOVE SP TO RET VAL
	RET

HALT

MULT


;==============
;	Vars
;==============
	STACK_START .fill x6000
	
	
.end
